import struct
from ctypes import create_string_buffer
from Util.util import checkACC2Byte

def SendHYB01PowerCode(breakCode, KongKaiCode, QBRunTime, QBPwm, SBRunTime, SBPwm, HDPwm, triRunCode):
    TxDataBuffer = create_string_buffer(16)
    TxDataBuffer[0] = b'\xAA'
    TxDataBuffer[1] = b'\x55'
    TxDataBuffer[2] = struct.pack('B', breakCode)
    TxDataBuffer[3] = struct.pack('B', KongKaiCode)
    QBRUNTIME = struct.pack('>H', QBRunTime)
    TxDataBuffer[4] = struct.pack('B', QBRUNTIME[0])
    TxDataBuffer[5] = struct.pack('B', QBRUNTIME[1])
    TxDataBuffer[6] = struct.pack('B', QBPwm)
    SBRUNTIME = struct.pack('>H', SBRunTime)
    TxDataBuffer[7] = struct.pack('B', SBRUNTIME[0])
    TxDataBuffer[8] = struct.pack('B', SBRUNTIME[1])
    TxDataBuffer[9] = struct.pack('B', SBPwm)
    TxDataBuffer[10] = struct.pack('B', HDPwm)
    TxDataBuffer[11] = struct.pack('B', triRunCode)
    TxDataBuffer[12] = b'\x55'
    TxDataBuffer[13] = b'\x55'
    ACC = checkACC2Byte(TxDataBuffer[:14])
    TxDataBuffer[14] = struct.pack('B', ACC[0])
    TxDataBuffer[15] = struct.pack('B', ACC[1])
    return TxDataBuffer